package com.example.myapplicationtest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
 
public class MainActivity extends Activity implements OnClickListener {
	private static final String TAG = "MainActivity";
	private TextView show;
	private Button getInt, getString, getIntArray, getBool, getBackIntArray,
			getBackStrArray, getObject;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		init();
	}
 
	private void init() {
		show = (TextView) this.findViewById(R.id.show);
		getInt = (Button) this.findViewById(R.id.getint);
		getInt.setOnClickListener(this);
		getIntArray = (Button) this.findViewById(R.id.getintarray);
		getIntArray.setOnClickListener(this);
		getString = (Button) this.findViewById(R.id.getstring);
		getString.setOnClickListener(this);
		getBool = (Button) this.findViewById(R.id.getbool);
		getBool.setOnClickListener(this);
		getBackIntArray = (Button) this.findViewById(R.id.getBackIntArray);
		getBackIntArray.setOnClickListener(this);
		getBackStrArray = (Button) this.findViewById(R.id.getBackStrArray);
		getBackStrArray.setOnClickListener(this);
		getObject = (Button) this.findViewById(R.id.getObject);
		getObject.setOnClickListener(this);
	}
 
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.getint:
			int intBack = JniClient.getInstance().AddInt(10, 10);
			showInfo(intBack);
			break;
 
		case R.id.getstring:
			String strBack = JniClient.getInstance().AddStr("program1",
					"program2");
			showInfo(strBack);
			break;
		case R.id.getintarray:
			int intArr = JniClient.getInstance().intArrayMethod(
					new int[] { 2, 5, 8 });
			showInfo(intArr);
			break;
		case R.id.getbool:
			boolean bool = JniClient.getInstance().booleanMethod(true);
			showInfo(bool);
			break;
		case R.id.getBackIntArray:
			int[] intBackArr = JniClient.getInstance().intMethod();
			showInfo(intBackArr);
			break;
		case R.id.getBackStrArray:
			String[] texts = JniClient.getInstance().stringMethod("java编程思想");
			for (int i = 0; i < texts.length; i++) {
				try {
					texts[i] = new String(texts[i].getBytes("ISO8859-1"), "GBK");
				} catch (Exception e) {
					e.printStackTrace();
				}
				showInfo(texts[i]);
			}
			System.out.println();
			break;
		case R.id.getObject:
			boolean object = JniClient.getInstance().objectMethod(
					"this is object data");
			showInfo(object);
			break;
 
		default:
			break;
		}
	}

	private void showInfo(Object object) {
		show.setText("" + object);
		Log.i(TAG, "返回的信息-->" + object);
	}


}


